/* 特殊字符*/
export function isvalidUsername (str) {
  const regName = /[~#^$@%&!*()<>:;'"{}【】 {2}]/
  return regName.test(str.trim())
}

/* 合法uri*/
export function validateURL (textval) {
  const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return urlregex.test(textval)
}

/* 合法IP*/
export function validateIP (textval) {
  const urlregex = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
  return urlregex.test(textval)
}

/* 小写字母*/
export function validateLowerCase (str) {
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/* 大写字母*/
export function validateUpperCase (str) {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/* 大小写字母*/
export function validatAlphabets (str) {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/* 数字*/
export function validatNum (str) {
  const reg = /^[0-9]+$/
  return reg.test(str)
}

/* 手机号*/
export function validatPhone (str) {
  const reg = /^1[3456789]\d{9}$/
  return reg.test(str)
}

/* 必须包含数字，大写字母，小写字母，特殊字符 */
export function isPassword (str) {
  const reg = /^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{15,100}$/
  return reg.test(str)
}

/* IP段 逗号分隔验证  */
export function isIpList (ips) {
  let reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
  let valdata = ips.split(',')
  let nd = true
  for (let i = 0; i < valdata.length; i++) {
    if (reg.test(valdata[i]) == false) {
      nd = false
    }
  }
  return nd
}

/* 非空 */
export function isEmptyValue (obj) {
  // 本身为空直接返回true
  if (obj == null) return true
  // 然后可以根据长度判断，在低版本的ie浏览器中无法这样判断。
  if (obj.length > 0) return false
  if (obj.length === 0) return true
  // 最后通过属性长度判断。
  for (let key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) return false
  }

  return true
}